//
//  PayEndData.m
//  Courses
//
//  Created by YiXuePxh on 15/4/22.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "PayEndData.h"
#import "Request.h"
@implementation PayEndData


-(id)initWithJsonDict:(NSDictionary* )jsonDict{
    self.orderId = jsonDict[@"orderId"];
    self.orderNo = jsonDict[@"orderNo"];
    self.orderTime = jsonDict[@"orderTime"];
    self.payTime = jsonDict[@"payTime"];
    self.orderStatus = jsonDict[@"orderStatus"];
    self.courseName = jsonDict[@"courseName"];
    self.classId = jsonDict[@"classId"];
    self.className = jsonDict[@"className"];
    self.classOpenDate = jsonDict[@"classOpenDate"];
    self.realAmount = jsonDict[@"realAmount"];
    self.discount = jsonDict[@"discount"];
    self.orderAmount = jsonDict[@"orderAmount"];
    self.mobile = jsonDict[@"mobile"];
    self.salesCode = jsonDict[@"salesCode"];
    self.invoiceType = jsonDict[@"invoiceType"];
    self.invoiceTitle = jsonDict[@"invoiceTitle"];
    self.invoiceAddress = jsonDict[@"invoiceAddress"];
    if ([jsonDict[@"coupons"] isKindOfClass:[NSArray class]]) {
        NSMutableArray* coupons = [[NSMutableArray alloc] init];
        for (id coupon in jsonDict[@"coupons"]) {
            NSString* couponCode = coupon[@"couponCode"];
            [coupons addObject:couponCode];
        }
        _coupons = [coupons mutableCopy];
        
    }
    return self;
}
+(PayEndData* )getPayDataBySourcId:(NSString* ) sourcId
                          DeciceNo:(NSString* ) deciceNo
                            UserId:(NSString* ) userId
                           OrderId:(NSString* ) orderId
                         PaymentNo:(NSString* ) paymentNo
                          TradeRtn:(NSString* ) tradeRtn
                           TradeId:(NSString* ) tradeId
                       TradeAmount:(NSString* ) tradeAmount
                         TradeTime:(NSString* ) tradeTiem{
    PayEndData* pay;
    Request* request = [Request requestWithName:@"pay_end"];
    request.body[@"sourceId"] = sourcId;
    request.body[@"deviceNo"] = deciceNo;
    NSDictionary* dicInfo = [[NSBundle mainBundle]infoDictionary];
    request.body[@"version"] = [dicInfo objectForKey:@"CFBundleShortVersionString"];
    request.body[@"userId"] = userId;
    request.body[@"orderId"] = orderId;
    request.body[@"paymentNo"] = paymentNo;
    request.body[@"tradeRtn"] = tradeRtn;
    request.body[@"tradeId"] = tradeId;
    request.body[@"tradeAmount"] = tradeAmount;
    request.body[@"tradeTime"] = tradeTiem;
    Response* response = [request response];
    if (!response.result) {
        return  nil;
    }
    
    if (response.result) {
        if ([response.content[@"order"] isKindOfClass:[NSDictionary class]]) {
            pay = [[PayEndData alloc] initWithJsonDict:response.content[@"order"]];
        }
    }
    
    return pay;

}



@end
